function with parameters python

26

# Here we define the function with a parameter
def greet(lang):
    if lang == 'spanish':
        print('Hola!')
    elif lang == 'french':
        print('Bonjour!')
    else:
        print('Hello!')

# Now we can call or invoke the function with different parameters
greet('spanish') # Output - Hola!
greet('french') # Output - Bonjour!
greet('english') # Output - Hello!

Comments

Submit
0 Comments